Page({
  data: {
    isPlayingMusic: false
  },
  bgm: null,
  music_url: 'https://abc.zhimalian.cn/%E5%92%8B%E4%BB%AC%E7%BB%93%E5%A9%9A%E5%90%A7.m4a',
  music_coverImgUrl: 'https://gitee.com/MarcoMaHH/color-cloud/raw/master/icon.jpg',
  onReady: function () {
    this.bgm = wx.getBackgroundAudioManager()
    this.bgm.title = '咋们结婚吧'
    this.bgm.epname = 'wedding'
    this.bgm.singer = '齐晨'
    this.bgm.coverImgUrl = this.music_coverImgUrl
    this.bgm.onCanplay(() => {
      this.bgm.pause()
    })
    this.bgm.src = this.music_url
  },
 onShow () {
    this.audioCtx = wx.createAudioContext('greetings');
    this.audioCtx.play()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide () {
   	// 当页面影藏时，暂停音乐
    this.audioCtx.pause()
  },
  play: function (e) {
    if (this.data.isPlayingMusic) {
      this.bgm.pause()
    } else {
      this.bgm.play()
    }
    this.setData({
      isPlayingMusic: !this.data.isPlayingMusic
    })
  },
})
